package com.init.bootframe.system.controller;

import com.init.bootframe.system.service.IMenuService;
import com.init.bootframe.system.vo.MenuVO;
import com.init.bootframe.system.vo.ModuleVO;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/menu")
public class MenuController {

    @Autowired
    private IMenuService menuService; //栏目service

    /**
     * 查询所有栏目列表
     * @param menuVO
     * @return
     * @throws Exception
     */
    @PostMapping("/findMenuList")
    public List<MenuVO> findMenuList(@RequestBody MenuVO menuVO) throws Exception {
        List<MenuVO> result = menuService.findMenuList(menuVO);
        return result;
    }

    /**
     * 查询用户所有栏目列表
     * @param menuVO
     * @return
     * @throws Exception
     */
    @PostMapping("/findUserMenuList")
    public List<MenuVO> findUserMenuList(@RequestBody MenuVO menuVO) throws Exception {
        List<MenuVO> result = menuService.findMenuListByUser(menuVO);
        return result;
    }

    /**
     * 添加栏目
     * @param menuVO
     * @return
     * @throws Exception
     */
    @PostMapping("/addMenu")
    public Map<String, Object> addMenu(@RequestBody MenuVO menuVO) throws Exception {
        Map<String, Object> result = menuService.addMenu(menuVO);
        return result;
    }

    /**
     * 编辑栏目
     * @param menuVO
     * @return
     * @throws Exception
     */
    @PostMapping("/updateMenu")
    public Map<String, Object> updateMenu(@RequestBody MenuVO menuVO) throws Exception {
        Map<String, Object> result = menuService.updateMenu(menuVO);
        return result;
    }

    /**
     * 修改批量栏目
     * @param menuJson
     * @return
     * @throws Exception
     */
    @RequestMapping(value="/updateBatchMenu",method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    public Map<String, Object> updateBatchMenu(@RequestBody String menuJson) throws Exception {
        Map<String, Object> result = menuService.updateBatchMenu(menuJson);
        return result;
    }

    /**
     * 栏目查询
     * @param menuVO
     * @return
     * @throws Exception
     */
    @PostMapping("/findMenu")
    public MenuVO findMenu(@RequestBody MenuVO menuVO) throws Exception {
        MenuVO result = menuService.findMenu(menuVO);
        return result;
    }

    /**
     * 栏目删除
     * @param menuVO
     * @return
     * @throws Exception
     */
    @PostMapping("/deleteMenu")
    public Map<String, Object> deleteMenu(@RequestBody MenuVO menuVO) throws Exception {
        Map<String, Object> result = menuService.deleteMenu(menuVO);
        return result;
    }

    /***************** 功能操作 ********************/

    /**
     * 添加功能
     * @param moduleVO
     * @return
     * @throws Exception
     */
    @PostMapping("/addModule")
    public Map<String, Object> addModule(@RequestBody ModuleVO moduleVO) throws Exception {
        Map<String, Object> result = menuService.addModule(moduleVO);
        return result;
    }

    /**
     * 修改功能
     * @param moduleVO
     * @return
     * @throws Exception
     */
    @PostMapping("/updateModule")
    public Map<String, Object> updateModule(@RequestBody ModuleVO moduleVO) throws Exception {
        Map<String, Object> result = menuService.updateModule(moduleVO);
        return result;
    }

    /**
     * 删除功能
     * @param moduleVO
     * @return
     * @throws Exception
     */
    @PostMapping("/deleteModule")
    public Map<String, Object> deleteModule(@RequestBody ModuleVO moduleVO) throws Exception {
        Map<String, Object> result = menuService.deleteModule(moduleVO);
        return result;
    }

    /**
     * 查询功能详细信息
     * @param moduleVO
     * @return
     * @throws Exception
     */
    @PostMapping("/findModule")
    public ModuleVO findModule(@RequestBody ModuleVO moduleVO) throws Exception {
        ModuleVO result = menuService.findModule(moduleVO);
        return result;
    }

    /**
     * 分页查询功能所有信息集合
     * @param moduleVO
     * @return
     * @throws Exception
     */
    @PostMapping("/findModules")
    public Map<String, Object> findModules(@RequestBody ModuleVO moduleVO) throws Exception {
        Map<String, Object> result = menuService.findModules(moduleVO);
        return result;
    }

    /**
     * 查询所有菜单下栏目功能信息
     * @param menuVO
     * @return
     * @throws Exception
     */
    @PostMapping("/findMenuModuleList")
    public List<MenuVO> findMenuModuleList(@RequestBody MenuVO menuVO) throws Exception {
        List<MenuVO> result = menuService.findMenuModuleList(menuVO);
        return result;
    }


}
